/**
 * 路由守卫
 */

import React from "react";
import RouterConfig from "./index.jsx";
import RouterBeforeConfig from "./RouterBeforeConfig";
import { Alert } from "antd";
import { useNavigate } from "react-router-dom";
export default function RouterBefore() {
  const res = RouterBeforeConfig.filter((item) => item.path === location.pathname)[0];
  const navigate = useNavigate();

  if (res) {
    if (res.needLogin && !localStorage.getItem("token")) {
      return <Alert message="请先登录" type="warning" closable afterClose={() => navigate("/")} />;
    }
  }

  return (
    <>
      <RouterConfig />
    </>
  );
}
